using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class EmployeeDetailModel : ModelBase
    {
        public EmployeeDetailModel()
        {
            client.GetSingleEmployeeCompleted += DoGetSingleEmployeeCompleted;
            client.InsertEmployeeCompleted += DoInsertEmployeeCompleted;
            client.UpdateEmployeeCompleted += DoUpdateEmployeeCompleted;
            client.GetRoleCollectionCompleted += DoGetRoleCollectionCompleted;
            client.GetEmploymentTypeCollectionCompleted += DoGetEmploymentTypeCollectionCompleted;
            client.GetAuthorizationCollectionCompleted += DoGetAuthorizationCollectionCompleted;
            client.ResetPasswordCompleted += DoResetPasswordCompleted;
            client.CheckIfUsernameExistsCompleted += DoCheckIfUsernameExistsCompleted;
        }

        #region  CheckIfUsernameExists

        public event EventHandler<FeedbackCompletedEventArgs> CheckIfUsernameExistsCompleted;

        public int CheckIfUsernameExistsAsync(string usernameToCheck)
        {
            client.CheckIfUsernameExistsAsync(usernameToCheck);
            return WebConstants.MagicNumer;
        }

        void DoCheckIfUsernameExistsCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (CheckIfUsernameExistsCompleted!=null)
            {
                CheckIfUsernameExistsCompleted(sender, e);
            }
        }

        #endregion

        #region ResetPassword

        public event EventHandler<FeedbackCompletedEventArgs> ResetPasswordCompleted;

        public int ResetPasswordAsync(Account account)
        {
            client.ResetPasswordAsync(account);
            return WebConstants.MagicNumer;
        }

        void DoResetPasswordCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (ResetPasswordCompleted != null)
            {
                ResetPasswordCompleted(sender, e);
            }
        }

        #endregion

        #region GetAuthorizationCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Authorization>> GetAuthorizationCollectionCompleted;

        public int GetAuthorizationCollectionAsync()
        {
            client.GetAuthorizationCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        private void DoGetAuthorizationCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Authorization> e)
        {
            if (GetAuthorizationCollectionCompleted != null)
            {
                GetAuthorizationCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region GetEmploymentTypeCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<EmploymentType>> GetEmploymentTypeCollectionCompleted;

        public int GetEmploymentTypeCollectionAsync()
        {
            client.GetEmploymentTypeCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        void DoGetEmploymentTypeCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<EmploymentType> e)
        {
            if (GetEmploymentTypeCollectionCompleted != null)
            {
                GetEmploymentTypeCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region GetRoleCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Role>> GetRoleCollectionCommpleted;

        public int GetRoleCollectionAsync()
        {
            client.GetRoleCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        void DoGetRoleCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Role> e)
        {
            if (GetRoleCollectionCommpleted != null)
            {
                GetRoleCollectionCommpleted(sender, e);
            }
        }

        #endregion

        #region UpdateEmployee

        public event EventHandler<FeedbackCompletedEventArgs> UpdateEmployeeCompleted;

        public int UpdateEmployeeAsync(Employee data)
        {
            client.UpdateEmployeeAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUpdateEmployeeCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UpdateEmployeeCompleted != null)
            {
                UpdateEmployeeCompleted(sender, e);
            }
        }

        #endregion

        #region InsertEmployee

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertEmployeeCompleted;

        public int InsertEmployeeAsync(Employee employee)
        {
            client.InsertEmployeeAsync(employee);
            return WebConstants.MagicNumer;
        }

        void DoInsertEmployeeCompleted(object sender, SingleFeedbackCompletedEventArgs<int> e)
        {
            if (InsertEmployeeCompleted!=null)
            {
                InsertEmployeeCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleEmployee

        public event EventHandler<SingleFeedbackCompletedEventArgs<Employee>> GetSingleEmployeeCompleted;

        public int GetSingleEmployeeAsync(int employeeID)
        {
            client.GetSingleEmployeeAsync(employeeID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleEmployeeCompleted(object sender, SingleFeedbackCompletedEventArgs<Employee> e)
        {
            if (GetSingleEmployeeCompleted != null)
            {
                GetSingleEmployeeCompleted(sender, e);
            }
        }

        #endregion
    }
}